package love.yuanmengrobot.guoyitanghoutai.util;

import java.math.BigInteger;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.UUID;

/**
 * 随机工具类
 *
 * @author LJH
 */
public class RandomUtils {
//    public static RandomUtils randomUtils=new RandomUtils();

    private static SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
    private static SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMddHHmmssSSS");
    private static SimpleDateFormat sdf3 = new SimpleDateFormat("yyyyMMddHHmmssSSS");
    private static SimpleDateFormat sdf4 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//标准时间
    private static SimpleDateFormat sdf5 = new SimpleDateFormat("mmssSSS");
    private static Random random = new Random();
    private static int number_100_999 = 100;

    /**
     * 得到当前日期
     */
    public static String getCurrentDateForString() {
        return sdf1.format(new Date());
    }


    /**
     * 生成文件名使用时间+4位随机数
     *
     * @param fileName 文件名称
     */
    public static String createFileNameUseTime(String fileName) {
        String fileSuffix = fileName.substring(fileName.lastIndexOf("."), fileName.length());
        String time = sdf2.format(new Date());
        Integer num = random.nextInt(9000) + 1000;
        return time + num + fileSuffix;
    }

    /**
     * 生成文件名使用UUID
     *
     * @param fileName 文件名称
     */
    public static String createFileNameUseUUID(String fileName) {
        String fileSuffix = fileName.substring(fileName.lastIndexOf("."), fileName.length());
        return UUID.randomUUID().toString().replace("-", "").toUpperCase() + fileSuffix;
    }


    public synchronized static String createId(String p) {
        number_100_999++;
        if (number_100_999 > 999) number_100_999 = 100;
        return p + sdf3.format(new Date()) + number_100_999;
    }

    //三十六进制返回
    public synchronized static String createIdOX(String p) {
        number_100_999++;
        if (number_100_999 > 999) number_100_999 = 100;
        String number = sdf3.format(new Date()) + number_100_999;


        BigInteger bigDecimal = new BigInteger(number);
        //压缩成三十六进制：bigDecimal.toString(36)

        /*解压
       String number=bigDecimal.toString(36);
        BigInteger bigDecimal2=new BigInteger(number,36);
        bigDecimal2. toString(10);//解
        */

        return p + bigDecimal.toString(36);
    }

    public static String getTime() {
        return sdf4.format(new Date());
    }
    public static String getNumberTime() {
        return sdf3.format(new Date());
    }


    public static void main(String[] args) {

//        System.out.println(sdf4.format(new Date()));
//        System.out.println(createIdOX("UC"));

    }

}
